package org.example.classtopia.Service.Impl;

import lombok.extern.slf4j.Slf4j;
import org.example.classtopia.Mapper.CourseMapper;
import org.example.classtopia.Model.Entity.Course;
import org.example.classtopia.Service.AiCourseAdviceService;
import org.example.classtopia.Service.ManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@Service
@Component
public class AiCourseAdviceServiceImpl implements AiCourseAdviceService {

    @Autowired
    private CourseMapper courseMapper;

    public List<Course> GetAllCourse(Long userId, String semester) {
        List<Course> courses = courseMapper.selectCourseByUserIdAndSemester(userId, semester);
        if(courses == null){
            return new ArrayList<>();
        }
        return courses;
    }

    public String GetPrompt(List<Course> courseList) {

        StringBuilder prompt = new StringBuilder();
        int count = 0;
        prompt.append("以下为我这个学期需要学习12周以上的课程，根据你对这些科目的理解，帮我给出每一门课的学习路径建议和安排，最好精确到周\n\n");

        for (Course course : courseList) {
            if(course.getEndWeek() - course.getStartWeek() + 1 >= 12 && course.getEventType().equals("course")) {
                prompt.append(course.getName()).append("\n");
                prompt.append("学习周数:").append(course.getEndWeek() - course.getStartWeek() + 1).append("\n");
                count++;
            }
        }

        if(count == 0){
            prompt.setLength(0);
            prompt.append("这是我这个学期要学习的科目，请帮我给出简单的学习路径建议");
            for(Course course : courseList){
                prompt.append(course.getName()).append("、");
            }
            prompt.append("\n");
        }

        return prompt.toString();
    }
}
